package com.ruoyi.project.doctors.controller;



import com.ruoyi.framework.security.LoginUser;
import com.ruoyi.framework.security.service.TokenService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.doctors.domain.Scheduling;
import com.ruoyi.project.doctors.domain.UserDoc;
import com.ruoyi.project.doctors.domain.dot.SchedulingFormDto;
import com.ruoyi.project.doctors.domain.dot.SchedulingRespDto;
import com.ruoyi.project.doctors.serivce.DoctSchedulingService;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/doctor/scheduling/")
public class DoctSchedulingController extends BaseController {
    @Autowired
    private DoctSchedulingService doctSchedulingService;

    @Autowired
    private TokenService tokenService;



    @GetMapping("queryUsersNeedScheduling")
    public AjaxResult queryUsersNeedScheduling(Long deptId){
        List<UserDoc> userDocList = doctSchedulingService.selectUserByDeptid(deptId);
        return AjaxResult.success(userDocList);

    }
    @GetMapping("queryDept")
    public AjaxResult queryDept(){
        return AjaxResult.success(doctSchedulingService.selectDeptByDeptId());
    }


    @GetMapping("queryScheduling")
    public AjaxResult queryScheduling(SchedulingRespDto schedulingRespDto){
        return AjaxResult.success(doctSchedulingService.getSchedulingData(schedulingRespDto));
    }

    @PostMapping("saveScheduling")
    public AjaxResult saveScheduling(@RequestBody SchedulingFormDto schedulingFormDto){
        return toAjax(doctSchedulingService.insertScheduling(schedulingFormDto));
    }

    @PostMapping("saveSchedulingNew")
    public AjaxResult saveSchedulingNew(@RequestBody Scheduling scheduling){
        return toAjax(doctSchedulingService.insertSchedulingNew(scheduling));
    }

    @GetMapping("queryMyScheduling")
    public AjaxResult queryMyScheduling(HttpServletRequest request, SchedulingRespDto schedulingRespDto){
        LoginUser loginUser = tokenService.getLoginUser(request);
        schedulingRespDto.setUserId(Integer.parseInt(loginUser.getUser().getUserId().toString()));
        schedulingRespDto.setDeptId(Integer.parseInt(loginUser.getUser().getPostId().toString()));
        System.out.println("getUserId:" + loginUser.getUser().getUserId());
        System.out.println("getDeptId:" + loginUser.getUser().getPostId());
        System.out.println("getQueryDate:" + schedulingRespDto.getQueryDate());
        return AjaxResult.success(doctSchedulingService.getSchedulingData(schedulingRespDto));
    }




}
